package com.ocean.array;

import java.util.Arrays;

/**
 * https://leetcode.cn/problems/move-zeroes/
 */
public class MoveZeroes2 {

    public static void main(String[] args) {
//        int[] height = new int[]{0};
        int[] height = new int[]{0, 1, 0, 3, 12};
        new MoveZeroes2().moveZeroes(height);
    }

    public void moveZeroes(int[] nums) {
        // 快慢指针
        int slow = 0;
        int fast = 1;
        while (fast < nums.length) {
            if (nums[slow] == 0) {
                // 慢指针要停下来
                if (nums[fast] != 0) {
                    // 交换
                    nums[slow] = nums[fast];
                    nums[fast] = 0;
                    slow++;
                }
            } else {
                slow++;
            }
            fast++;

        }
        System.out.println(Arrays.toString(nums));
    }
}
